<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/6/25 12:19
 */

namespace App\Transformers;

use App\Models\Hospital;
use Illuminate\Database\Eloquent\Builder;
use League\Fractal\TransformerAbstract;

class HospitalTransformer extends TransformerAbstract
{
    /**
     * @param \App\Models\Hospital $hospital
     * @return array
     */
    public function transform($hospital)
    {
        if ($hospital instanceof Builder) {

            return $hospital->first()->toArray();
        } elseif ($hospital instanceof Hospital) {

            return [
                'id'   => $hospital->id,
                'name' => $hospital->name,
            ];
        }

        throw new \RuntimeException('参数错误', 500);
    }
}